import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {SubscribeForm, SubscribeQuery, SubscribeVO} from '@/api/crawler/subscribe/types';

/**
 * 查询爬虫订阅列表
 * @param query
 * @returns {*}
 */

export const listSubscribe = (query?: SubscribeQuery): AxiosPromise<SubscribeVO[]> => {
  return request({
    url: '/crawler/subscribe/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询爬虫订阅详细
 * @param id
 */
export const getSubscribe = (id: string | number): AxiosPromise<SubscribeVO> => {
  return request({
    url: '/crawler/subscribe/' + id,
    method: 'get'
  });
};

/**
 * 新增爬虫订阅
 * @param data
 */
export const addSubscribe = (data: SubscribeForm) => {
  return request({
    url: '/crawler/subscribe',
    method: 'post',
    data: data
  });
};

/**
 * 修改爬虫订阅
 * @param data
 */
export const updateSubscribe = (data: SubscribeForm) => {
  return request({
    url: '/crawler/subscribe',
    method: 'put',
    data: data
  });
};

/**
 * 删除爬虫订阅
 * @param id
 */
export const delSubscribe = (id: string | number | Array<string | number>) => {
  return request({
    url: '/crawler/subscribe/' + id,
    method: 'delete'
  });
};

/**
 * 运行爬虫
 * @param id
 */
export const runCrawler = (id: string | number | Array<string | number>) => {
  return request({
    url: '/crawler/subscribe/run/' + id,
    method: 'get'
  });
};
